package restaurant;

import java.util.ArrayList;

public class Simulation implements Runnable {
	// Simulation Parameters
	int clock_tick_countdown;
	int customer_flow;
	boolean running;
	private int clock_tick_reset;
	private int cust_arrival_countdown;
	private int order_submitted_countdown;
	private int order_preparation_countdown;

	SystemInterface system;
	Invoker invoker = new Invoker();

	public Simulation(SystemInterface sys) {
		system = sys;
		clock_tick_reset = 500;
		clock_tick_countdown = clock_tick_reset;
		customer_flow = 5;
		running = false;
	}

	public void sim_start() {
		running = true;
	}

	public void sim_stop() {
		running = false;
	}

	@Override
	public void run() {
		while (running) {
			clock_tick_countdown = clock_tick_countdown - 1;

			if (clock_tick_countdown == 0) {
				advance_simulation();
				clock_tick_countdown = clock_tick_reset;
			}
		}
	}

	void advance_simulation() {
		// Random randNum = new Random();
		int randNum = (int) Math.random() * 5;
		cust_arrival_countdown--;
		order_submitted_countdown--;
		// ArrayList<Customer> cust_queue = new ArrayList<Customer>();
		//
		// String name = "";
		// int num_tables = 0;
		// if (cust_arrival_countdown == 0) {
		// int num_people = randNum.nextInt(8) + 1;
		// // add num_people to cust_queue
		//
		// Customer customer = new Customer(name, num_tables);
		// custqueue.add(customer);
		// }
		//
		// if (order_preparation_countdown == 0) {
		// // dequeue orders_queue;
		// // update tables_info;
		// }



		system.requestTable(name, numberInParty);
		ArrayList<Table> availtables = invoker.getAvailableTables();
		if (availtables.isEmpty()) 
		{
			// place customer in queue

		} 
		else 
		{
			system.activateTable(tableNo, pin);

		}


		String menu = system.getMenu();
		system.orderItem(tableNo, itemNo, price);


		system.itemUp(orderNo);
		system.orderPickup(tableNo);
		
		system.rateItem(itemNo, rating, comment);
		
		system.payTab(tableNo, cardNumber, expiration);
	}

	public static void main(String[] args) {
		SystemInterface sys = new SystemInterface();

		Thread sim_process = new Thread(new Simulation(sys), "main thread");
		sim_process.start();
	}
}